package com.itheima.controller;


import com.itheima.domain.Permission;
import com.itheima.domain.Product;
import com.itheima.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;


/*
* 资源权限
* */
@Controller
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private PermissionService permissionService;


    /* 资源权限查询*/
    @RequestMapping("/findAll.do")
    public ModelAndView findAll() throws Exception{
        ModelAndView mv = new ModelAndView();
        List<Permission> permissions = permissionService.findAll();
        mv.addObject("permissionList",permissions);
        mv.setViewName("permission-list");
        return mv;
    }

    //资源权限详细信息查询
    @RequestMapping("/findByPermissionId.do")
    public ModelAndView findByPermissionId(String id) throws Exception{
        ModelAndView mv = new ModelAndView();
        Permission permission = permissionService.findByPermissionId(id);
        mv.addObject("permission",permission);
        mv.setViewName("permission-show");
        return mv;
    }

    //资源权限添加
    @RequestMapping("/save.do")
    public String save(Permission permission) throws Exception{
        permissionService.save(permission);
        return "redirect:findAll.do";
    }


}
